<!-- #INCLUDE File="lib.asp" -->

<%

' never get this page from cache
Response.ExpiresAbsolute=DateAdd("yyyy", 00, Date)

command = request("command")
theUser = "politie" 'request.servervariables("AUTH_USER")
session("loggedUser") = theUser

select case command
case ""
	header
	
	%><table border=0><tr><td><%
	
	response.write("<h1>Programma kiezen</h1>")
	
	sql = "select * from live order by id desc"
	set rs = tmpConnection.execute(sql)
	rs.movefirst
	liveOne = rs("titel")
	liveUser = rs("user")
	liveDatum = rs("datum")
	liveDatumDisp = day(liveDatum) & "-" & month(liveDatum) & "-" & year(liveDatum)
	rs.close
	set rs = nothing
	
	response.write("<p>Gebruiker:&nbsp;" & theUser & "</p>")
	%><p class="opm">Nu op de <%=PRODUCTNAME%>: programma "<%=liveOne%>", live gezet d.d. <%=liveDatumDisp%> door <%=ucase(liveUser)%>.</p><%

	sql = "select * from programs order by titel"
	set rs = tmpConnection.execute(sql)
	rs.movefirst
	tel = 0
	%><table cellspacing="0"><tr><td>
	<form name="frmProg" action="editor.asp?command=editprog" method="post">
	<%
	while not rs.eof
		tel = tel + 1
		titel = rs("titel")
		id = rs("id")
		if titel = liveOne then
			%><input checked type="Radio" name="program" value="<%=id%>"><b><%=titel%></b><br><%
		else
			%><input type="Radio" name="program" value="<%=id%>"><%=titel%><br><%
		end if
		rs.movenext
	wend
	%>
	<input type="Radio" name="program" value="-1">
	<input type="text" name="newname" value="" onclick="document.frmProg.program[<%=tel%>].checked = true;"> (nieuw programma)<br>
	<br><input type="button" value="Selekteer" onclick="go();">
	</form>
	</td>
	
	</tr></table>
	
	<hr>
	<font class="opm">noot: het vetgedrukte programma is momenteel op de <%=PRODUCTNAME%> te zien</font>
	
	<script language="JavaScript">
		function go() {
			selektie = false;
			for (t=0;t<=<%=tel%>;t++) {
				if (document.frmProg.program[t].checked) selektie = true;
			}
			if (selektie) {
				if (document.frmProg.program[<%=tel%>].checked && document.frmProg.newname.value == "") {
					alert("Vul eerst een naam van het nieuwe programma in.");
					document.frmProg.newname.focus();
				} else {
					document.frmProg.submit();
				}
			} else {
				alert("U heeft nog geen keuze gemaakt");
			}
		}
	</script>
	
	<td valign="top" align="right">
	<br>&gt;&gt;&gt;&nbsp;<a href="editor.asp?command=archive"><font color="Black"><b>Archief van de <%=PRODUCTNAME%></b></font></a>
	<br>&gt;&gt;&gt;&nbsp;<a href="editor.asp?command=showlog"><font color="Black"><b>Logbestand van vandaag</b></font></a>
	<br>&gt;&gt;&gt;&nbsp;<a href="editor.asp?command=showloglive"><font color="Black"><b>Logbestand live gezet</b></font></a>
	<br><br><font color="red"><b>Berichten:</b></font><br>
	<iframe src="about:blank" width="300" height="80" name="messageframe"></iframe>
	<br>&gt;&gt;&gt;&nbsp;<a href="action.asp?command=msgcompose"><font color="Black"><b>Laat een bericht achter</b></font></a>
	</td>
	
	</td></tr></table>
	<%
	closeDatabase
case "showlog"
	call showLog(now())
case "showloglive"
	call showLogLive()
case "imgman"
	program = request("program")
	call manageImages()
case "toggleimg"
	program = request("program")
	toggleImage(request("id"))
case "editprog"
	program = request("program")
	if program = "" then response.redirect("editor.asp")
	if program = "-1" then
		' nieuw programma
		newname = request("newname")
		sql = "insert into programs (titel,creator,created) values ('" & newname & "','" & theUser & "','"& now() & "')"
		rs = tmpConnection.execute(sql)
		sql = "select * from programs order by id desc"
		set rs = tmpConnection.execute(sql)
		rs.movefirst
		newnr = rs("id")
		rs.close
		set rs = nothing
		progname = newname
		tmpLine = ""
		progArray = split(tmpLine, ";")
		program = newnr
		dispProgram(progArray)
		closeDatabase
	else
		sql = "select * from programs where id=" & program
		rs = tmpConnection.execute(sql)
		tmpLine = rs("volgorde")
		if isnull(tmpLine) then tmpLine=""
		progname = rs("titel")
		progArray = split(tmpLine, ";")
		dispProgram(progArray)
		closeDatabase
	end if
case "makelive"
	program = request("program")
	sql = "select * from programs where id=" & program
	rs = tmpConnection.execute(sql)
	tmpLine = rs("volgorde")
	titel = rs("titel")
	nu = now()
	' update the LIVE table

	'sql = "insert into live (datum, volgorde, user, titel) values ('" & extnow & "','" & tmpLine & "','" & theUser & "','" & titel & "')"
	sql = "insert into live (datum, volgorde, [user], titel) values ('" & now() & "','" & tmpLine & "','" & theUser & "','" & titel & "')"
	tmpConnection.execute(sql)

	call register(0, "==================================================")
	call register(0, "LIVE GEZET: " & titel)
	call register(0, "==================================================")
	
	call registerCentral(0, "LIVE GEZET: " & titel)
	
	' open a connection for the Archive table
	openArchive
	' open a connection for the online table
	openOnline
	' remove the date from the ARCHIVE and ONLINE table
	m = month(nu)
	d = day(nu)
	if m < 10 then m = "0" & m
	if d < 10 then d = "0" & d
	nu = year(nu) & m & d '  left(extdate,8)
	sql = "delete from archive where datum='" & nu & "'"
	archiveConnection.execute(sql)
	onlineConnection.execute(sql)
	' update the ARCHIVE table
	thePageArray = split(tmpLine, ";")
	for t=lbound(thePageArray) to ubound(thePageArray)
		sql = "select * from content where id=" & thePageArray(t)
		set rs = tmpConnection.execute(sql)
		update = "insert into archive (datum,titel,inhoud,background,special,creator,created,modifier,modified,volgnr) values ("
		titel = replace(rs("titel"),"'","''")
		inhoud = replace(rs("inhoud") & "","'","''")
		special = rs("special")
		created = rs("created")
		modified = rs("modified")
		if not isdate(modified) then modified = now()
		if not isdate(created) then created = now()
		if not isnumeric(special) then special = 0
		update = update & "'" & nu & "'," & "'" & titel & "','" & inhoud & "'," & rs("background") & "," & special & ",'" & rs("creator") & "','" & created & "','" & modifier & "','" & modified & "'," & t & ")"
		archiveConnection.execute(update)
		onlineConnection.execute(update)
		' call register(0, update)
	next
	closeArchive
	
	' now clean op the ONLINE table, so only 1 week old dates remain
	sql = "select * from archive where volgnr=0 order by datum desc"
	set rs = onlineConnection.execute(sql)
	t = 0
	while not rs.eof and t<=30
		marker = rs("datum")
		rs.movenext
		t = t + 1
	wend
	removesql = "delete from archive where datum < '" & marker & "'"
	onlineConnection.execute(removesql)
	
	' duplicate the images to the archive
	sql = "delete from images"
	onlineConnection.execute(sql)
	sql = "select * from images"
	set rs = tmpConnection.execute(sql)
	while not rs.eof
		sql = "insert into images (id, image) values (" & rs("id") & ",'" & replace(rs("image"), "'", "''") & "')"
		onlineConnection.execute(sql)
		rs.movenext
	wend
	closeDatabase
	closeOnline
	
	response.redirect("editor.asp?command=editprog&program=" & program)
case "editpage"
	program = request("program")
	position = request("position")
	editPage(position)
case "savepage"
	program = request("program")
	page = request("page")
	titel = replace(request("titel"),"'","''")
	inhoud = replace(request("inhoud"),"'","''")
	inhoud = replace(inhoud, vbcrlf, "<br>")
	background = request("background")
	special = request("special")
	dur = request("dur")
	if (dur = "") then
		sql = "update content set titel='" & titel & "', inhoud='" & inhoud & "', background=" & background & ", special=" & special & ", modifier='" & theUser & "', modified='" & now() & "', dur=NULL where id=" & page
	else
		sql = "update content set titel='" & titel & "', inhoud='" & inhoud & "', background=" & background & ", special=" & special & ", modifier='" & theUser & "', modified='" & now() & "', dur=" & dur & " where id=" & page
	end if
	tmpConnection.execute(sql)
	closeDatabase
	response.redirect("editor.asp?command=editprog&program=" & program)
case "newpage"
	program = request("program")
	sql = "insert into content (titel,background,special,creator,created) values ('Pagina " & now() & "',1,0,'" & theUser & "','" & now() & "')"
	tmpConnection.execute(sql)
	sql = "select id from content order by id desc"
	set nrs = tmpConnection.execute(sql)
	nrs.movefirst
	newnr = nrs("id")
	sql = "select * from programs where id=" & program
	rs = tmpConnection.execute(sql)
	tmpLine = rs("volgorde")
	if isnull(tmpLine) then tmpLine = ""
	tmpLine = trim(tmpLine)
	if trim(tmpLine) = "" then
		newLine = newnr
	else
		newLine = tmpLine & ";" & newnr
	end if
	sql = "update programs set volgorde='" & newLine & "' where id=" & program
	tmpConnection.execute(sql)
	editpage(newnr)
case "remove"
	program = request("program")
	position = request("position")
	sql = "select * from programs where id=" & program
	rs = tmpConnection.execute(sql)
	tmpLine = rs("volgorde")
	progArray = split(tmpLine, ";")
	newLine = ""
	for t=lbound(progArray) to ubound(progArray)
		if t <> cint(position) then
			if newLine = "" then
				newLine = progArray(t)
			else
				newLine = newLine & ";" & progArray(t)
			end if
		end if
	next
	sql = "update programs set volgorde='" & newLine & "' where id=" & program
	tmpConnection.execute(sql)
	closeDatabase
	response.redirect("editor.asp?command=editprog&program=" & program)
case "insert"
	program = request("program")
	position = request("position")
	header
	%><h1>Pagina invoegen</h1>
	<h2>Selekteer pagina om in  te voegen:</h2>
	<form name="frmInvoegen" method="post" action="editor.asp?command=insert2&program=<%=program%>&position=<%=position%>">
	<select name="invoegen"><%
	sql = "select id,titel from content order by lcase(titel)"
	set rs = tmpConnection.execute(sql)
	rs.movefirst
	while not rs.eof
		%><option value="<%=rs("id")%>"><%=rs("titel")%></option><%
		rs.movenext
	wend
	rs.close
	set rs = nothing
	%></select>
	<input type="submit" value="OK">
	</form>
	
	<%
	terug()
	closeDatabase
case "insert2"
	program = request("program")
	position = request("position")
	invoegen = request("invoegen")
	sql = "select * from programs where id=" & program
	rs = tmpConnection.execute(sql)
	tmpLine = rs("volgorde")
	if isnull(tmpLine) then tmpLine = ""
	progArray = split(tmpLine, ";")
	if cint(position) = -1 then
		newLine = invoegen
	else
		newLine = ""
	end if
	for t=lbound(progArray) to ubound(progArray)
		if newLine = "" then
			newLine = progArray(t)
		else
			newLine = newLine & ";" & progArray(t)
		end if
		if t = cint(position) then
			newLine = newLine & ";" & invoegen
		end if
	next
	sql = "update programs set volgorde='" & newLine & "' where id=" & program
	tmpConnection.execute(sql)
	closeDatabase
	response.redirect("editor.asp?command=editprog&program=" & program)
case "archive"
	header
	openArchive
	sql = "select * from archive where volgnr=1 order by datum"
	set rs = archiveConnection.execute(sql)
	response.write("<h1>Archief " & PRODUCTNAME & "</h1>")

	'zoekform
	%><form action="editor.asp?command=zoek" method="post">Zoek: <input type="text" name="zoekterm"> <input type="submit" value="Zoek"><br><%

	' openen hoofdtabel
	response.write("<table><tr>")

	tab = "<table align='center' style='background-color: #EEEEEE;'>"
	col = 0
	vmaand = -1
	maandcol = 1
	week = "<tr style='font-weight: bold;'><td style='border: 1px solid silver;'>Zo</td><td style='border: 1px solid silver;'>Ma</td><td style='border: 1px solid silver;'>Di</td><td style='border: 1px solid silver;'>Wo</td><td style='border: 1px solid silver;'>Do</td><td style='border: 1px solid silver;'>Vr</td><td style='border: 1px solid silver;'>Za</td></tr>"
	tab = tab & "<tr>"
	while not rs.eof
		datum = rs("datum")
		yy = mid(datum,1,4)
		mm = mid(datum,5,2)
		dd = mid(datum,7,2)
		realdate = cdate(dd & "-" & mm & "-" & yy)
		if vmaand <> mm then
			if vmaand <> -1 then
				' vorige maand uitvullen
				for t = col+1 to 7
					tab = tab & "<td>&nbsp;</td>"
				next
				'tab = tab & "<tr><td colspan=7>&nbsp;</td></tr>"
			
				tab = tab & "</tr></table>" ' afmaken tab
				' tonen tab
				response.write vbcrlf & vbcrlf & "<td width='180' height='150' align='center' valign='top' style='background-color: #EEEEEE'>" & tab & "</td>" & vbcrlf
				maandcol = maandcol + 1
				if maandcol = 4 then
					response.write "</tr><tr>"
					maandcol = 1
				end if
				' uitvullen tussenliggende maanden
				for t = vmaand + 1 to mm -1
					tab = "<table><tr><td colspan='7' style='color: blue'><b>" & monthname(t) & " " & yy & "</b></td></tr>" & week & "</table>"
					response.write vbcrlf & vbcrlf & "<td height='150' valign='top' style='background-color: #EEEEEE'>" & tab & "</td>" & vbcrlf
					maandcol = maandcol + 1
					if maandcol = 4 then
						response.write "</tr><tr>"
						maandcol = 1
					end if
				next
				' opnieuw starten tab
				tab = "<table align='center' style='background-color: #EEEEEE;'>"
			end if
			tab = tab & "<tr><td colspan=7 style='color: blue'><b>" & monthname(mm) & " " & yy & "</b></td></tr>"
			tab = tab & week

			' uitvullen voor juiste weekdag
			for t = 1 to weekday(realdate)-1
				col = col + 1
				tab = tab & "<td>&nbsp;</td>"
			next
			col = weekday(realdate)-1
		end if
		while col <> weekday(realdate)-1
		' er vallen data tussenuit, uitvullen
			col = col + 1
			if col = 7 then
				tab = tab & "</tr><tr>"
				col = 0
			end if
			tab = tab & "<td align='center' style='border: 1px solid black; background-color: silver'>-</td>"
		wend
		tab = tab & "<td style='border: 1px solid black; background-color: silver'><a href='editor.asp?command=archivecontent&day=" & datum & "'>" & dd & "</a></td>"
		col = col + 1
		if col = 7 then
			tab = tab & "</tr><tr>"
			col = 0
		end if
		rs.movenext
		vmaand = mm
	wend
	while col < 7
		tab = tab & "<td>&nbsp;</td>"
		col = col + 1
	wend
	' afmaken tab	
	tab = tab & "</tr></table>"
	' tonen tab
	response.write vbcrlf & vbcrlf & "<td width='180' height='150' align='center' valign='top' style='background-color: #EEEEEE'>" & tab & "</td>" & vbcrlf
	maandcol = maandcol + 1
	' afmaken hoofdtabel
	while maandcol < 4
		response.write("<td>&nbsp;</td>")
		maandcol = maandcol + 1
	wend
	response.write ("</tr></table>")
	%><br>
	<a href="editor.asp"><font color="Black">Terug naar invoer...</font></a><%
	closeArchive
	closeDatabase
case "archivecontent"
	header
	openArchive
	datum = request("day")
	yy = mid(datum,1,4)
	mm = mid(datum,5,2)
	dd = mid(datum,7,2)
	sql = "select * from archive where datum='" & datum & "' order by volgnr"
	set rs = archiveConnection.execute(sql)
	response.write("<h1>Archief " & PRODUCTNAME & "</h1>")
	response.write("<table cellpadding=3 cellspacing=0>")
	response.write("<tr><td colspan=2><br><b>" & PRODUCTNAME & " van " & dd & " " & monthname(mm) & " " & yy & "</b></td></tr>")
	while not rs.eof
		'if not (left(rs("titel"),1) = "(" and right(rs("titel"),1) = ")") then
			pagina=rs("volgnr")
			response.write("<tr><td>&nbsp;</td><td style='background-color: gray;'><a href='editor.asp?command=archivepage&day=" & datum & "&pag=" & pagina & "'>" & rs("volgnr") & ". " & rs("titel") & "</a></td></tr>")
		'end if
		rs.movenext
	wend
	response.write("</table>")
	%><br>
	<%
	terug()
	closeArchive
	closeDatabase
case "archivepage"
	header
	openArchive
	datum = request("day")
	pagina = request("pag")
	sql = "select * from archive where datum='" & datum & "' and volgnr=" & pagina & " order by volgnr"
	set rs = archiveConnection.execute(sql)
	response.write("<h1>Archief " & PRODUCTNAME & "</h1>")
	response.write("<h2>Moment...</h2>")
	%>
	<script language="JavaScript">
	function pagePreview() {
		imgnr = <%=rs("background")%>;
		special = <%=rs("special")%>;
		titel = "<%=rs("titel")%>";
		inhoud2 = "<%
tmp = replace(rs("inhoud"),"""","\""")
tmp = replace(tmp, "%", "%25")
response.write tmp
%>";
		
		window.open("kabelkrant.asp?command=preview&titel=" + titel + "&inhoud=" + inhoud2 + "&imgnr=" + imgnr + "&special=" + special, "popUp", "fullscreen=yes, scrollbars=no");
		history.go(-1);
	}
	pagePreview();
	</script>
	<%
	closeArchive
	closeDatabase
case "inventory"
	header
	%><h1>Afbeeldingen inventariseren</h1><%
	pad = Server.MapPath(".\images")
	Set fs = CreateObject("Scripting.FileSystemObject")
	Set folder = fs.getfolder(pad)
	listStart = false
	Set Image = Server.CreateObject("csImageFile.Manage")
	for each file in folder.files
		if len(file.name) <= 50 then
		sql = "select * from images where image='" & replace(file.name, "'", "''") & "'"
		set rs = tmpConnection.execute(sql)
		if rs.eof then
			select case file.name
			case "left.gif", "right.gif", "stop.gif", "stoplink.gif"
				' system image, ignore!
			case else
				' image is new, create query
				sql = "insert into images (image) values ('" & replace(file.name, "'", "''") & "')"
				tmpConnection.execute(sql)
				if not listStart then
					response.write "<ol>"
					listStart = true
				end if
				response.write "<li><b>" & file.name & "</b> in database opgenomen</li>"
			end select
		end if
		if not fs.fileexists(pad & "\thumbs\" & file.name) OR not fs.fileexists(pad & "\www\" & file.name) then
			' create the thumb
			Image.ReadFile pad & "\" & file.name
			Image.Resize 496, 280 '380, 280
			Image.WriteFile pad & "\thumbs\" & file.name
			if not listStart then
				response.write "<ol>"
				listStart = true
			end if
			response.write "<li><b>" & file.name & "</b> als thumbnail 496x280 voor website aangemaakt</li>"
			' copy the thumb so it can be uploaded to the website
			if not fs.fileexists(pad & "\www\" & file.name) then
				fs.copyfile pad & "\thumbs\" & file.name, pad & "\www\" & file.name
				response.write "<li><b>" & file.name & "</b> klaargezet voor upload</li>"
			end if
		end if
		else
			response.write "<li><b>" & file.name & "</b> NIET VERWERKT: bestandsnaam is te lang!  (" & len(file.name) & " tekens, mag max 50)</li>"
		end if
	next
	Set Image = nothing
	if listStart then 
		response.write "</ol>"
	else
		response.write "<p>Afbeeldingendatabase is up-to-date.</p>"
	end if
	%><hr><%
	terug()
	Set folder = nothing
	Set fs = nothing
	closeDatabase
	footer
case "zoek"
	header
	openArchive
	term = request.form("zoekterm")
	sql = "select * from archive where titel like '%" & term & "%' or inhoud like '%" & term & "%' order by datum desc"
	set rs = archiveConnection.execute(sql)
	lastyy = 0
	lastmm = 0
	response.write("<h1>Archief " & PRODUCTNAME & "</h1>")
	response.write("<h2>Zoekterm: '" & term & "'</h2>")
	%><table cellpadding=3><%
	while not rs.eof
		datum = rs("datum")
		yy = mid(datum,1,4)
		mm = mid(datum,5,2)
		dd = mid(datum,7,2)
		fulldate = yy & "-" & mm & "-" & dd
		realdate = cdate(dd & "-" & mm & "-" & yy)
		link = "<a href='editor.asp?command=archivepage&day=" & datum & "&pag=" & rs("volgnr") &"'><font color='black'>" & rs("titel") & "</font></a>"
		if yy <> lastyy then
			if lastyy <> 0 then response.write "<tr><td colspan=3>&nbsp;</td></tr>"
			%><tr><td colspan=3 class=h1><%=yy%></td></tr>
			<tr><td colspan=3>&nbsp;</td></tr><%
			lastmm = 0
		end if
		if mm <> lastmm then
			if lastmm <> 0 then response.write "<tr><td colspan=3>&nbsp;</td></tr>"
			%><tr><td colspan=3 class=h2><b><%=monthname(mm)%></b></td></tr><%
		end if
		%>
		<tr>
		<td><%=dagkort(realdate)%></td>
		<td><%=fulldate%></td>
		<td><%=link%></td>
		</tr>
		<%
		lastyy = yy
		lastmm = mm
		rs.movenext
	wend
	%></table><br><hr><%
	rs.close
	closeArchive
	terug()
	footer
case else
	%>I don't know what you mean with "<%=command%>".<%
end select

sub showLog(d)
	header
	response.write("<h1>Logbestand " & PRODUCTNAME & " van " & d &"</h1>")

	set fs = CreateObject("Scripting.FileSystemObject")
	fname = server.mappath("log\" & serverLogname(d) & ".log")

	set file = fs.openTextFile(fname, 1) ' 8=forReading
	
	response.write "<table border=""1"" width=""80%"">"
	while not file.atendofstream
		ln = file.readline
		ln = replace(ln, "-" & left(d,4) & " ", "-" & left(d,4) & "</td><td>")
		ln = replace(ln, " [", "</td><td>")
		ln = replace(ln, "] ", "</td><td>")
		ln = replace(ln, "][", " ")
		response.write "<tr><td>" & ln & "</td></tr>"
	wend
	response.write "</table>"

	file.close
	set file = nothing
	set fs = nothing
	
	response.write "<br>"
	terug
	footer
end sub

sub showLogLive()
	header
	response.write("<h1>Logbestand " & PRODUCTNAME & " live gezet</h1>")

	set fs = CreateObject("Scripting.FileSystemObject")
	fname = server.mappath("log\kkserver.log")

	set file = fs.openTextFile(fname, 1) ' 8=forReading
	
	response.write "<table border=""1"" width=""80%"">"
	while not file.atendofstream
		ln = file.readline
		ln = replace(ln, "-" & left(d,4) & " ", "-" & left(d,4) & "</td><td>")
		ln = replace(ln, " [", "</td><td>")
		ln = replace(ln, "] ", "</td><td>")
		ln = replace(ln, "][", " ")
		response.write "<tr><td>" & ln & "</td></tr>"
	wend
	response.write "</table>"

	file.close
	set file = nothing
	set fs = nothing
	
	response.write "<br>"
	terug
	footer
end sub

sub terug()
	%><a href="javascript:history.go(-1);"><font color="Black">Terug...</font></a><%
end sub

sub terugNaarMenu()
	%><a href="editor.asp?command=editprog&program=<%=program%>"><font color="Black">Terug...</font></a><%
end sub

sub dispProgram(theArray)
	header
	%>
	<script language="JavaScript">
		function makeLive(id) {
			if (confirm("Klik op OK om dit programma op de <%=PRODUCTNAME%> te zetten. De geselekteerde pagina's worden dan uitgezonden."))
			self.location.href = "editor.asp?command=makelive&program=" + id;
		}
	</script>
	<%
	aantPages = ubound(theArray) - lbound(theArray) + 1 
	response.write("<h1>Programma aanpassen</h1>")
	response.write("<h2>" & progname & " (" & program & ")</h2>")
	response.write("<hr>")
	response.write("<table border='0' cellpadding='2' celspacing='2'><tr>")
	vak = 1
	response.write("<td colspan='2' align='center' bgcolor='purple' class='indexcel'>BEGIN</td>")
	response.write("<td><a href='editor.asp?command=insert&position=-1&program=" & program & "'><img src='images/right.gif' alt='voeg pagina in' border='0'></a></td>")
	for t=lbound(theArray) to ubound(theArray)
		sql = "select * from vwcontent where id=" & theArray(t)
		rs = tmpConnection.execute(sql)
		vak = vak + 1
		if not isnull(rs("schemaid")) then ' heeft schema
			bgcolor = "#6699ff"
			schovz = "<table><tr>"
			for each dag in Array("ma", "di", "wo", "do", "vr", "za", "zo")
				schovz = schovz & "<td class=dag>"
				if rs(dag) then 
					schovz = schovz & ucase(left(dag,1))
				else
					schovz = schovz & "&nbsp;&nbsp;"
				end if
				schovz = schovz & "</td>"
			next
			schovz = schovz & "</tr><tr class=indexcel><td colspan=7 class='indexcel' align='center'>"
			if DBStringToShortDate(rs("van")) <> "" then
				if DBStringToShortDate(rs("tot")) <> "" then
					schovz = schovz & "van " & DBStringToShortDate(rs("van")) & " t/m " & DBStringToShortDate(rs("tot")) & "</td>"
				else
					schovz = schovz & "vanaf " & DBStringToShortDate(rs("van")) & "</td>"
				end if
			else
				if DBStringToShortDate(rs("tot")) <> "" then
					schovz = schovz & "t/m " & DBStringToShortDate(rs("tot")) & "</td>"
				else
					schovz = schovz & "alle datums</td>"
				end if
			end if
			schovz = schovz & "</tr>"
			schovz = schovz & "</table>"
		else
			bgcolor = "blue"
			schovz = ""
		end if
		tmpTitel = rs("titel") & ""
		if trim(tmpTitel) = "" then tmpTitel = "(geen titel)"
		response.write("<td width='10' bgcolor='" & bgcolor & "'><a href='editor.asp?command=remove&position=" & t & "&program=" & program & "'><img src='images/stoplink.gif' alt='verwijder van deze plek' border='0'></a></td>")
		response.write("<td height='50' align='center' width='170' bgcolor='" & bgcolor & "' class='indexcel'><a href='editor.asp?command=editpage&position=" & theArray(t) & "&program=" & program & "'>" & tmpTitel & "</a>" & schovz & "</td>")
		response.write("<td><a href='editor.asp?command=insert&position=" & t & "&program=" & program & "'><img src='images/right.gif' alt='voeg pagina in' border='0'></a></td>")
		if vak = 5 then
			response.write("</tr>" & vbcrlf & "<tr><td colspan='15' height='10'>&nbsp;</td></tr>" & vbcrlf & "<tr>")
			vak = 0
		end if
	next 
	vak = vak + 1
	response.write("<td colspan='2' height='50' align='center' bgcolor='purple' class='indexcel'>EINDE</td>")
	vak = vak + 1
	for t=vak to 5
		response.write("<td>&nbsp;</td>")
	next
	response.write("</tr></table>")
	response.write("<hr>")
	response.write("<a href='editor.asp'><font color='black'>Ander programma</font></a>")
	response.write(" | <a href='editor.asp?command=newpage&program=" & program & "'><font color='black'>Nieuwe pag.</font></a>")
	if aantPages > 0 then
		response.write(" | <a href='javascript:makeLive(" & program & ");'><font color='black'>Deze volgorde op de " & PRODUCTNAME & "</font></a>")
	end if
	response.write(" | <a href='editor.asp?command=inventory'><font color='black'>Afbeeldingenbestand bijwerken</font></a>")
	response.write(" | <a href='editor.asp?command=imgman&program=" & program & "'><font color='black'>Afbeeldingenlijst</font></a>")
	footer
end sub

sub manageImages()
	header
	
	%><h1>Afbeeldingenlijst</h1>
	<p>Deze afbeeldingen kunt u selekteren uit het lijstje (dropdown) als achtergrond van een <%=PRODUCTNAME%> pagina. 
	Op deze pagina kunt u bepalen of een afbeelding wel of niet in de lijst voorkomt. 
	Dit doet u door het vinkje aan of uit te zetten.
	Het aan of uitzetten van een afbeelding heeft verder geen invloed op de <%=PRODUCTNAME%> of website.</p>
	<p>Als u op de naam van de afbeelding klikt, ziet u een voorbeeld.</p><%
	
	terugNaarMenu
	
	' toon de plaatjes in de lijst
	%><a name="welles"><h3>Afbeeldingen in de lijst</h3></a>
	<p><a href="#nietes"><font color="Black">naar: afbeeldingen NIET in de lijst...</font></a></p><%
	call listImages("select * from images where listed order by image")
	
	%><a name="nietes"><h3>Afbeeldingen NIET in de lijst</h3></a>
	<p><a href="#welles"><font color="Black">naar: afbeeldingen wel in de lijst...</font></a></p><%
	' toon de plaatjes die niet in de lijst staan
	call listImages("select * from images where not listed order by image")
	
	%><br><hr><%
	terugNaarMenu
	footer
end sub

sub listImages(sql)
	set rs = tmpConnection.execute(sql)
	t = 0
	c = 0
	%><table border=0><tr><%
	while not rs.eof
		%>
		<td><input type="checkbox" <% if rs("listed") then response.write "checked" %> onclick="location.href='editor.asp?command=toggleimg&id=<%=rs("id")%>&program=<%=program%>'"></td>
		<td width=200><a href="javascript:preview('<%=rs("image")%>');"><font color="Black"><%=rs("image")%></font></a></td><%
		t=t+1
		c=c+1
		rs.movenext
		if c=3 then
			%></tr><%
			if not rs.eof then
				%><tr><%
				c = 0
			end if
		end if
	wend
	for u=c+1 to 3
		%><td colspan=2>&nbsp;</td><%
	next
	%></tr><%=vbcrlf%>
	<tr><td>*</td><td colspan=5><%=t%> afbeelding<% if t<>1 then response.write "en" %></td></tr>
	</table><%
end sub

sub toggleImage(id)
	tmpConnection.execute("update images set listed = not listed where id=" & id)
	response.redirect("editor.asp?command=imgman&program=" & program)
end sub

sub editPage(page)
	sql = "select dur from content where id=" & page
	rs = tmpConnection.execute(sql)
	dur = rs("dur")
	
	sql = "select * from vwcontent where id=" & page
	rs = tmpConnection.execute(sql)
	titel = rs("titel")
	inhoud = rs("inhoud")
	if isnull(inhoud) then inhoud=""
	inhoud = replace(inhoud,"<br>",vbcrlf)
	background = rs("background")
	special = rs("special")
	if isnull(special) then special=0
	header
	%>
<form name="frmEdit" method="post" action="editor.asp?command=savepage&program=<%=program%>">
<h2>Pagina <%=page%> aanpassen</h2>
<input type="hidden" name="page" value="<%=page%>">

<input class="titel" type="text" size="30" name="titel" value="<%=titel%>">
<br>
<span class="opm">als u de tekst tussen haakjes () zet, wordt deze niet weergegeven</span>
<br><br>

<table><tr><td valign="top">
<textarea class="inhoud" name="inhoud" rows="11" cols="60"><%=inhoud%></textarea>
<br><font class="opm">Om een tabel te maken kunt u het '~'-symbool gebruiken als TAB<br>
Voor een euro-symbool kunt u [euro] intikken.</font>
</td><td valign="top">
<img border="1" name="preview" src="" width="176" height="100">
<br>Achtergrondplaatje:<br>

<!-- ACHTERGRONDPLAATJE -->
<select name="background" onchange="imgPreview(this.value);" style="font-size: 11px; width: 200px;">
<%
sql = "select * from images where listed or id=" & background & " order by image"
set imgrs = tmpConnection.execute(sql)
imgrs.movefirst
script = ""
while not imgrs.eof
	if imgrs("id") = background then
		plaatje = imgrs("image")
		%><option selected value="<%=imgrs("id")%>"><%=imgrs("image")%></option><%
	else
		%><option value="<%=imgrs("id")%>"><%=imgrs("image")%></option><%
	end if
	script = script & "if (num==" & imgrs("id") & ") document.preview.src='images/thumbs/" & replace(imgrs("image"),"'", "\'") & "';" & vbcrlf
	imgrs.movenext
wend
imgrs.close
set imgrs = nothing
%></select>

<!--SPECIALS -->
<br><br>Speciale pagina's:<br>
<select name="special" onchange="checkTijd()" style="font-size: 11px; width: 200px;">
<% if special=0 then %>
<option selected value="0">Normale pagina</option>
<% else %>
<option value="0">Normale pagina</option>
<% end if %>
<%
sql = "select * from special order by titel"
set sprs = tmpConnection.execute(sql)
sprs.movefirst
while not sprs.eof
	if special = sprs("id") then
		%><option selected value="<%=sprs("id")%>"><%=sprs("titel")%></option><%
	else
		%><option value="<%=sprs("id")%>"><%=sprs("titel")%></option><%
	end if
	sprs.movenext
wend
sprs.close
set sprs = nothing
%>
</select>

<!-- TIJD -->
<span id="dur0">
<br>
<br>Weergavetijd:
<br><font class="opm">Laat leeg voor de standaard tijd,<br>standaard tekst: 18 sec en enkel plaatjes: 9 sec</font><br>
<input type="text" size="10" name="dur" value="<%=dur%>"> seconden
</span>
<BR>

<!-- UITZENDSCHEMA -->
<br>
<% if not isnull(rs("schemaid")) then %>
<br><strong>Deze pagina volgt een uitzendschema</strong><br>
<a href="javascript:show_window2('schema.asp?id=<%=rs("schemaid")%>&now=<%=now()%>)', 'schema', 540, 380);"><font color="#000000">Aanpassen...</font></a> | <a href="schema.asp?command=delschema&id=<%=rs("schemaid")%>&position=<%=page%>&program=<%=program%>"><font color="#000000">Verwijderen</font></a>
<% else %>
<strong>Uitzendschema</strong><br>
<a href="javascript:show_window2('schema.asp?command=new&id=<%=page%>', 'schema', 540, 380);"><font color="#000000">Aanmaken...</font></a>
<% end if %>

</td></tr></table>
<br>
<input type="Button" value="Voorbeeld" onclick="pagePreview();">
<input type="Button" value="Bewaar" onclick="bewaar();">
</form>

<% terug() %>

<script language="JavaScript">
document.preview.src = "images/thumbs/<%=plaatje%>";
checkTijd();

function checkTijd() {
	if (document.frmEdit.special.value == "0") {
		document.frmEdit.dur.disabled = false;
		document.all["dur0"].style.visibility = "visible";
	} else {
		document.frmEdit.dur.value = "";
		document.frmEdit.dur.disabled = true;
		document.all["dur0"].style.visibility = "hidden";
	}
}

function show_window2(whichpage, namepage, winwidth, winheight) {
	window.open (whichpage, namepage, 'scrollbars=yes,resizable=1,status=no,toolbar=no,location=no,menubar=no,width=' + winwidth + ',height=' + winheight + '')
}

function imgPreview(num) {
<%=script%>
}

function pagePreview() {
	imgnr = document.frmEdit.background.value;
	special = document.frmEdit.special.value;
	titel = document.frmEdit.titel.value;
	inhoud1 = document.frmEdit.inhoud.value;
	inhoud2 = "";
	regels = 1;
	for (t=0;t<=inhoud1.length;t++) {
		c = inhoud1.substring(t,t+1);
		if (c == '\n') {
			inhoud2 = inhoud2 + "<br>";
			regels = regels + 1;
		} else {
			if (c=="&") {
				inhoud2 = inhoud2 + "%26";
			} else {
				if (c=="%") {
					inhoud2 = inhoud2 + "%25";
				} else {
					inhoud2 = inhoud2 + c;
				}
			}
		}
	}
	if (regels <= 15) {
		window.open("kabelkrant.asp?command=preview&thispage=<%=page%>&titel=" + titel + "&inhoud=" + inhoud2 + "&imgnr=" + imgnr + "&special=" + special, "popUp", "fullscreen=yes, scrollbars=no, width=1365, height=768");
	} else {
		alert("U kunt niet meer dan 15 regels gebruiken!");
	}
}

function bewaar() {
	inhoud1 = document.frmEdit.inhoud.value;
	inhoud2 = "";
	regels = 1;
	for (t=0;t<=inhoud1.length;t++) {
		c = inhoud1.substring(t,t+1);
		if (c == '\n') {
			inhoud2 = inhoud2 + "<br>";
			regels = regels + 1;
		} else {
			inhoud2 = inhoud2 + c;
		}
	}
	if (regels <= 15) {
		document.frmEdit.submit();
	} else {
		alert("U kunt niet meer dan 15 regels gebruiken!");
	}
}

</script>
	<%
	footer
	closeDatabase
end sub

%>